package com.example.demoback.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Quarter;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demoback.common.Result;
import com.example.demoback.entity.Abnormal;
import com.example.demoback.entity.Penalty;
import com.example.demoback.entity.Serious;
import com.example.demoback.entity.User;
import com.example.demoback.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/echarts")
public class EchartsController {

    @Autowired
    private IBasicService basicService;//基础信息
    @Autowired
    private ILicenseService licenseService;//行政许可信息
    @Autowired
    private IPenaltyService penaltyService;//行政处罚信息
    @Autowired
    private IAbnormalService abnormalService;//经营异常信息
    @Autowired
    private  ISeriousService seriousService;//严重失信信息


    public Result get(){
        Map<String,Object> map = new HashMap<>();
        map.put("x", CollUtil.newArrayList("a","b","c"));
        map.put("y",CollUtil.newArrayList(1,2,3));
        return Result.success();
    }

    @GetMapping("/members1")
    public Result members() {
//        List<User> list = iUserService.list();
//        int q1 = 0; // 第一季度
//        int q2 = 0; // 第二季度
//        int q3 = 0; // 第三季度
//        int q4 = 0; // 第四季度



//        for (User user : list) {
//            Date createTime = user.getCreateTime();
//            Quarter quarter = DateUtil.quarterEnum(createTime);
//            switch (quarter) {
//                case Q1: q1 += 1; break;
//                case Q2: q2 += 1; break;
//                case Q3: q3 += 1; break;
//                case Q4: q4 += 1; break;
//                default: break;
//            }
//        }

        long q1 = abnormalService.count();

        long q3 = seriousService.count();
        long q4 = licenseService.count();

        long q2 = abnormalService.count()-q1-q3-q4+50;

        return Result.success(CollUtil.newArrayList(q1, q2, q3, q4));
    }

    @GetMapping("/members2")
    public Result members2() {

        long q1 = licenseService.count();
        long q2 = abnormalService.count();
        long q3 = seriousService.count();



        return Result.success(CollUtil.newArrayList(q1, q2, q3));
    }


//echarts1图标传值
    @GetMapping("/get1")
    public Result get1(){

//        List<String> list = new ArrayList<String>();
//        list.add("2017");   //索引为0  //.add(e)
//        list.add("2018");    //索引为1
//        list.add("2019");    //索引为2
//        list.add("2020");   //索引为3
//        list.add("2021");    //索引为4
//        list.add("2022");    //索引为5
//        Map<String,Object> map = new HashMap<>();
//        map.put("x", CollUtil.newArrayList("2017","2018","2019","2020","2021","2022"));
//        map.put("penalty",CollUtil.newArrayList(1,2,3));
//        map.put("abnormal",CollUtil.newArrayList(1,2,3));
//        map.put("serious",CollUtil.newArrayList(1,2,3));

        QueryWrapper<Penalty> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.like("penaltytime","2017");
        long a1 = penaltyService.count(queryWrapper1);

        QueryWrapper<Penalty> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.like("penaltytime","2018");
        long a2 = penaltyService.count(queryWrapper2);

        QueryWrapper<Penalty> queryWrapper3 = new QueryWrapper<>();
        queryWrapper3.like("penaltytime","2019");
        long a3 = penaltyService.count(queryWrapper3);

        QueryWrapper<Penalty> queryWrapper4 = new QueryWrapper<>();
        queryWrapper4.like("penaltytime","2020");
        long a4 = penaltyService.count(queryWrapper4);

        QueryWrapper<Penalty> queryWrapper5 = new QueryWrapper<>();
        queryWrapper5.like("penaltytime","2021");
        long a5 = penaltyService.count(queryWrapper5);

        QueryWrapper<Penalty> queryWrapper6 = new QueryWrapper<>();
        queryWrapper6.like("penaltytime","2022");
        long a6 = penaltyService.count(queryWrapper6);


        return Result.success(CollUtil.newArrayList(a1,a2,a3,a4,a5,a6));

    }

    @GetMapping("/get2")
    public Result get2(){

//        map.put("abnormal",CollUtil.newArrayList(1,2,3));

        QueryWrapper<Abnormal> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.like("abnormalmakingdate","2017");
        long a1 =abnormalService.count(queryWrapper1);

        QueryWrapper<Abnormal> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.like("abnormalmakingdate","2018");
        long a2 = abnormalService.count(queryWrapper2);

        QueryWrapper<Abnormal> queryWrapper3 = new QueryWrapper<>();
        queryWrapper3.like("abnormalmakingdate","2019");
        long a3 = abnormalService.count(queryWrapper3);

        QueryWrapper<Abnormal> queryWrapper4 = new QueryWrapper<>();
        queryWrapper4.like("abnormalmakingdate","2020");
        long a4 = abnormalService.count(queryWrapper4);

        QueryWrapper<Abnormal> queryWrapper5 = new QueryWrapper<>();
        queryWrapper5.like("abnormalmakingdate","2021");
        long a5 = abnormalService.count(queryWrapper5);

        QueryWrapper<Abnormal> queryWrapper6 = new QueryWrapper<>();
        queryWrapper6.like("abnormalmakingdate","2022");
        long a6 = abnormalService.count(queryWrapper6);


        return Result.success(CollUtil.newArrayList(a1,a2,a3,a4,a5,a6));

    }

    @GetMapping("/get3")
    public Result get3(){


        QueryWrapper<Serious> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.like("seriousmakingdate","2017");
        long a1 =seriousService.count(queryWrapper1);

        QueryWrapper<Serious> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.like("seriousmakingdate","2018");
        long a2 = seriousService.count(queryWrapper2);

        QueryWrapper<Serious> queryWrapper3 = new QueryWrapper<>();
        queryWrapper3.like("seriousmakingdate","2019");
        long a3 = seriousService.count(queryWrapper3);

        QueryWrapper<Serious> queryWrapper4 = new QueryWrapper<>();
        queryWrapper4.like("seriousmakingdate","2020");
        long a4 = seriousService.count(queryWrapper4);

        QueryWrapper<Serious> queryWrapper5 = new QueryWrapper<>();
        queryWrapper5.like("seriousmakingdate","2021");
        long a5 = seriousService.count(queryWrapper5);

        QueryWrapper<Serious> queryWrapper6 = new QueryWrapper<>();
        queryWrapper6.like("seriousmakingdate","2022");
        long a6 = seriousService.count(queryWrapper6);


        return Result.success(CollUtil.newArrayList(a1,a2,a3,a4,a5,a6));

    }
}
